class_name ItemDB
extends Resource

@export var item_json:JSON 


func get_version() -> String:
	return item_json.data["version"]

func get_item_info(id:String) -> Dictionary:
	return item_json.data["items"][id]

func create_effective_by_item_info(id:String) -> EffectiveBase:
	var item_info = get_item_info(id) as Dictionary
	var effective_id = item_info["effective_id"]
	# 创建物品需要的effective
	var effective_db:EffectiveDB = load("res://datamodel/effective/effective_db.tres")
	var item_effective =  effective_db.create_effective_instance(effective_id) 
	## 根据id获取到类型 根据类型取出所有参数 
	for index in effective_db.get_effective_arg_count(effective_id) :
		var name = effective_db.get_effective_arg_name(effective_id, index)
		#var type = effective_db.get_effective_arg_type(effective_id, index)
		#if type == "float" :
		var v = get_item_info(id)["effective_args"][name] as float
		item_effective.set(name, v)

	return item_effective
		
func get_item_descp_with_arg(id:String) -> String:
	var item_info = get_item_info(id) as Dictionary
	var descp = item_info["description"] as String
	var effective_id = item_info["effective_id"]
	var effective_db:EffectiveDB = load("res://datamodel/effective/effective_db.tres")
	
	var descp_arg_array:Array = []
	for index in effective_db.get_effective_arg_count(effective_id) :
		var name = effective_db.get_effective_arg_name(effective_id, index) as String
		#var type = effective_db.get_effective_arg_type(effective_id, index)
		#if type == "float" :
		var v = get_item_info(id)["effective_args"][name] as float
		descp_arg_array.append([name,v])
		#descp.replace("{="+name+"=}", String(v))
	print(descp_arg_array)
	return descp.format(descp_arg_array)
	

